﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;

namespace Besture.UI
{
    public partial class SeoSet : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            //页面加载
            InitPage();
            //编辑编号
            InitData(ID);
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 页面加载
        /// </summary>
        public void InitPage()
        {
			
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            if (id == 0) return;

            var dac = new SeoDac();
            var model = dac.GetModel(id);

            txtSeoKey.Text = model.SeoKey.ToString();
			txtSeoValue.Text = model.SeoValue.ToString();
			

			//ControlSeo.SeoTitle = model.SeoTitle;
			//ControlSeo.SeoKeywords = model.SeoKeywords;
			//ControlSeo.SeoDescription = model.SeoDescription;
            txtSeoTitle.Text = model.SeoTitle;
            txtSeoKeywords.Text = model.SeoKeywords;
            txtSeoDescription.Text = model.SeoDescription;
        }
        #endregion

        #region 保存

        protected void BtnSubmitClick(object sender, EventArgs eventArgs)
        {
            var dac = new SeoDac();
            SeoModel model=null;
            var baseDac = new BaseDac<SeoModel>();
            //添加
            if (!EditPage)
            {
                model = new SeoModel();
                model.SeoKey = txtSeoKey.Text.Trim();
				model.SeoValue = txtSeoValue.Text.Trim();
                model.SeoTitle = txtSeoTitle.Text.Trim();
                model.SeoKeywords = txtSeoKeywords.Text.Trim();
                model.SeoDescription = txtSeoDescription.Text.Trim();


                //加载添加基本数据
                baseDac.LoadAddBaseModel(model);
				//加载SEO基本数据
				//baseDac.LoadSeo(model, ControlSeo.SeoTitle, ControlSeo.SeoKeywords, ControlSeo.SeoDescription);

                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(ID);
                model.SeoKey = txtSeoKey.Text.Trim();
				model.SeoValue = txtSeoValue.Text.Trim();
                model.SeoTitle = txtSeoTitle.Text.Trim();
                model.SeoKeywords = txtSeoKeywords.Text.Trim();
                model.SeoDescription = txtSeoDescription.Text.Trim();


                //加载修改基本数据
                baseDac.LoadUpdateBaseModel(model);
				//加载SEO基本数据
				//baseDac.LoadSeo(model, ControlSeo.SeoTitle, ControlSeo.SeoKeywords, ControlSeo.SeoDescription);

                dac.Update(model);
            }

            FunHelper.Alert("Save Success", ListUrl());
        }
        #endregion
    }
}